<?php

/**
 * BKloud Framework
 * Core_Controller abstract class
 * 
 * LICENSE:
 * BKloud Framework duoc xay dung va phat trien boi nhom BKloud - dai hoc bach khoa Ha Noi 
 * Ban duoc phep su dung framework nay cho muc dich hoc tap , nghien cuu va cac ung dung phi thuong mai
 * 
 * @copyright Copyright (c) 2011 BKloud - HPCC.
 * @version 0.1
 */
abstract class Core_Controller
{
    /**
     * View to use
     *
     * @var Core_Template
     */
    protected $_view;

    /**
     * Registry to use
     *
     * @var Core_Registry
     */
    protected $_registry;

    /**
     * Http to use
     *
     * @var Core_Http
     */
    protected $_http;

    /**
     * baseUrl to use
     *
     * @var string
     */
    protected $_baseUrl;

    public function __construct()
    {

        $this->_registry = Core_Registry::singleton();
        $this->_http     = $this->_registry['http'];
        $this->_view     = $this->_registry['template'];
        $this->_baseUrl     = '';
        $baseUrl            = $this->_http->getBaseUrl();
        if($baseUrl != '')
        $this->_baseUrl     = '/' .$baseUrl ;
    }

    /**
     *Redirect To Another URL 
     *
     * @param $path 
     * @var void
     */
    public function redirect($path)
    {
        if (strpos($path, $this->_baseUrl) !== 0)
            $path = $this->_baseUrl . $path;
        header("Location: $path");
    }
}
